#ifndef STM32F10X_MD
        #define STM32F10X_MD
#endif
#ifndef USE_STDPERIPH_DRIVER
        #define USE_STDPERIPH_DRIVER
#endif

#include "Application.h"
#include "Error.h"
#include "GScrolledWindow.h"
#include "Leds.h"
#include "Network.h"

int
main(void)
{
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
        /* 创建主应用对象 */
        Application *app = application_new_from_global();
        /* 创建初始化滚动窗口，显示初始化信息 */
        GWidget *scwin = g_scrolled_window_new();
        // g_widget_set_margin(scwin, 10);
        /* 滚动窗口添加信息自动渲染 */
        g_scrolled_window_set_auto_render(G_SCROLLED_WINDOW(scwin), true);
        g_scrolled_window_add_text(G_SCROLLED_WINDOW(scwin),
                                   "Connecting WiFi...");

        /* 创建网络对象 */
        Network *net = network_new_from_global();
        /* 连接网络调用钩子 */
        network_signal_connect(net, app, NETWORK_HANDLER(app_net_handler_cb));
        /* 连接到 WiFi */
        network_connect_wifi(net, "SUSE_Faker", "as2134ukey");

        g_scrolled_window_add_text(G_SCROLLED_WINDOW(scwin),
                                   "Connected successful.");
        g_scrolled_window_add_text(G_SCROLLED_WINDOW(scwin),
                                   "Connecting TCP server...");

        /* 连接到云平台 */
        network_connect_server(net, "47.109.94.67", "2933");
        if (!(network_get_flags(net) & NETWORK_FLAGS_CONNECTED_TCP)) {
                leds_set_byte(leds_new_from_global(), 0x01);
                if (ERROR_HAVED) {
                        g_scrolled_window_add_text(G_SCROLLED_WINDOW(scwin),
                                                   error);
                }
                while (1)
                        ;
        }
        g_scrolled_window_add_text(G_SCROLLED_WINDOW(scwin),
                                   "Connect server success.");

        /* 云平台中注册充电桩的设备 */
        network_send(net,
                     "zncdz,devType=EMB,msgType=REG,devID=esp01s-0016,progress,"
                     "power,voltage,temp,balance,ctime=00:00:00,restime=00:00:"
                     "00,inrev,mode");
        /* 应用实例连接到可用的网络对象 */
        application_connect_network(app, net);
        /* 开始接收云平台的消息，并推送数据信息到云平台 */
        while (1)
                application_loop_once(app);
}
